﻿using Shake.Business.Infrastructures;
using Shake.Domain.Models;
using Shake.Framework.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Shake.Framework.Database;
using Shake.Framework.Models;

namespace Shake.Business.Services
{
    public class FlightService : IFlightService
    {
        public IRepository Repository { get; set; }

        public PaginationContent GetFlights(PageArgument pageArg)
        {
            var results = Repository.Query<FlightTx>().OrderByDescending(t => t.DepartureTime).Page(pageArg);

            return results;
        }

        public void Update(List<FlightTx> tx)
        {
            Repository.UpdateMany(tx);
        }

        public void Remove(List<FlightTx> tx)
        {
            Repository.DeleteMany(tx);
        }

        public void Create(List<FlightTx> tx)
        {
            tx.ForEach(t => t.Id = Guid.NewGuid().ToString("N"));
            Repository.InsertMany(tx);
        }
    }
}
